#灰度图像大律法使用例程
import sensor, image, time,machine
from pyb import LED

sensor.reset()
sensor.set_vflip(False)
sensor.set_hmirror(False)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000.
sensor.skip_frames(time = 2000)     # WARNING: If you use QQVGA it may take seconds
clock = time.clock()                # to process a frame sometimes.


LED(1).on()
LED(2).on()
LED(3).on()

'''
for i in range(60):
    img = sensor.snapshot()
    histogram = img.get_histogram()
    Thresholds = histogram.get_threshold()
    l = Thresholds.l_value()

    print(Thresholds)
'''

while(True):
    clock.tick()
    img = sensor.snapshot()
    '''帧率会低很多
    img = sensor.snapshot().lens_corr(strength = 0.5, zoom = 1.0)
    img.bilateral(3,color_sigma=0.1,space_sigma=0.1)#采用双边滤波
    img.gaussian(3, unsharp=True,)#图像消除锐化
    '''
    histogram = img.get_histogram()
    Thresholds = histogram.get_threshold()
    l = Thresholds.l_value()
    print(Thresholds)
    img.binary([(0, l)])
